package xyz.labmem.app.unit

import javafx.event.EventHandler
import javafx.scene.control.TextArea
import javafx.scene.image.ImageView
import javafx.scene.layout.VBox
import xyz.labmem.app.config.AppConfig.uiImage
import xyz.labmem.app.main.CenterPane
import xyz.labmem.app.main.MainApplication
import xyz.labmem.lipx.core.tool.LogInfo


/**
 * @author       : ltty
 * @description  :
 * @createDate   : 2024/11/12
 */
class HomePageUnit(parent: CenterPane) : VBox() {

    init {
        prefHeightProperty().bind(parent.prefHeightProperty())
        prefWidthProperty().bind(parent.prefWidthProperty().subtract(230))
        val img = ImageView(uiImage["bg1"]).apply {
            isPreserveRatio = true
            fitWidthProperty().bind(this@HomePageUnit.prefWidthProperty())
        }
        children.addAll(img,TextArea().apply {
            isWrapText = true
            isEditable=false
            prefWidthProperty().bind(this@HomePageUnit.prefWidthProperty().multiply(.66))
            prefHeightProperty().bind(this@HomePageUnit.prefHeightProperty().subtract(img.fitHeightProperty()))
            LogInfo.logs.addListener { _,_,log->
                appendText("""
                    ${log.last()}
                """.trimIndent())
                positionCaret(text.length)
            }
        })
        img.onMouseClicked = EventHandler {
            MainApplication.hostServices?.showDocument("https://gitee.com/labmem000/lipx-desktop")
        }
    }

}